
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>PostgreSQL 特有模型索引 &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../../../genindex.html" />
    <link rel="search" title="搜索" href="../../../search.html" />
    <link rel="next" title="PostgreSQL 特有查找" href="lookups.html" />
    <link rel="prev" title="PostgreSQL 特有数据库函数" href="functions.html" />



 
<script src="../../../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="functions.html" title="PostgreSQL 特有数据库函数">previous</a>
     |
    <a href="../../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="lookups.html" title="PostgreSQL 特有查找">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-postgres-indexes">
            
  <div class="section" id="s-module-django.contrib.postgres.indexes">
<span id="s-postgresql-specific-model-indexes"></span><span id="module-django.contrib.postgres.indexes"></span><span id="postgresql-specific-model-indexes"></span><h1>PostgreSQL 特有模型索引<a class="headerlink" href="#module-django.contrib.postgres.indexes" title="永久链接至标题">¶</a></h1>
<p>以下是 PostgreSQL 特有的 <a class="reference internal" href="../../models/indexes.html"><span class="doc">索引</span></a> 可以从 <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.indexes</span></code> 模块中获得。</p>
<div class="section" id="s-bloomindex">
<span id="bloomindex"></span><h2><code class="docutils literal notranslate"><span class="pre">BloomIndex</span></code><a class="headerlink" href="#bloomindex" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.contrib.postgres.indexes.BloomIndex">
<em class="property">class </em><code class="descname">BloomIndex</code>(<em>*expressions</em>, <em>length=None</em>, <em>columns=()</em>, <em>**options</em>)<a class="headerlink" href="#django.contrib.postgres.indexes.BloomIndex" title="永久链接至目标">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 3.1.</span> </div>
<p>创建一个 <a class="reference external" href="https://www.postgresql.org/docs/current/bloom.html">bloom</a> 索引。</p>
<p>要使用这个索引访问，你需要激活 PostgreSQL 上的 <a class="reference external" href="https://www.postgresql.org/docs/current/bloom.html">bloom</a> 扩展。你可以使用 <a class="reference internal" href="operations.html#django.contrib.postgres.operations.BloomExtension" title="django.contrib.postgres.operations.BloomExtension"><code class="xref py py-class docutils literal notranslate"><span class="pre">BloomExtension</span></code></a> 迁移操作来安装它。</p>
<p>为 <code class="docutils literal notranslate"><span class="pre">length</span></code> 参数提供一个从 1 到 4096 的整数位，用于指定每个索引条目的长度。PostgreSQL 的默认值是 80。</p>
<p><code class="docutils literal notranslate"><span class="pre">columns</span></code> 参数取一个元组或最多 32 个值的列表，这些值是 1 到 4095 的整数位。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.2:</span> <p>增加了位置参数 <cite>*expressions</cite>，以支持函数索引。</p>
</div>
</dd></dl>

</div>
<div class="section" id="s-brinindex">
<span id="brinindex"></span><h2><code class="docutils literal notranslate"><span class="pre">BrinIndex</span></code><a class="headerlink" href="#brinindex" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.contrib.postgres.indexes.BrinIndex">
<em class="property">class </em><code class="descname">BrinIndex</code>(<em>*expressions</em>, <em>autosummarize=None</em>, <em>pages_per_range=None</em>, <em>**options</em>)<a class="headerlink" href="#django.contrib.postgres.indexes.BrinIndex" title="永久链接至目标">¶</a></dt>
<dd><p>创建一个 <a class="reference external" href="https://www.postgresql.org/docs/current/brin-intro.html">BRIN 索引</a> 。</p>
<p>将 <code class="docutils literal notranslate"><span class="pre">autosummarize</span></code> 参数设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，启用 autovacuum 进行 <a class="reference external" href="https://www.postgresql.org/docs/current/brin-intro.html#BRIN-OPERATION">自动汇总</a> 。</p>
<p><code class="docutils literal notranslate"><span class="pre">pages_per_range</span></code> 参数取一个正整数。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.2:</span> <p>增加了位置参数 <cite>*expressions</cite>，以支持函数索引。</p>
</div>
</dd></dl>

</div>
<div class="section" id="s-btreeindex">
<span id="btreeindex"></span><h2><code class="docutils literal notranslate"><span class="pre">BTreeIndex</span></code><a class="headerlink" href="#btreeindex" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.contrib.postgres.indexes.BTreeIndex">
<em class="property">class </em><code class="descname">BTreeIndex</code>(<em>*expressions</em>, <em>fillfactor=None</em>, <em>**options</em>)<a class="headerlink" href="#django.contrib.postgres.indexes.BTreeIndex" title="永久链接至目标">¶</a></dt>
<dd><p>创建一个 B 树索引。</p>
<p>为 <a class="reference external" href="https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS">fillfactor</a> 参数提供一个从  10 到 100 的整数值，以调整索引页的打包程度。PostgreSQL 的默认值是 90。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.2:</span> <p>增加了位置参数 <cite>*expressions</cite>，以支持函数索引。</p>
</div>
</dd></dl>

</div>
<div class="section" id="s-ginindex">
<span id="ginindex"></span><h2><code class="docutils literal notranslate"><span class="pre">GinIndex</span></code><a class="headerlink" href="#ginindex" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.contrib.postgres.indexes.GinIndex">
<em class="property">class </em><code class="descname">GinIndex</code>(<em>*expressions</em>, <em>fastupdate=None</em>, <em>gin_pending_list_limit=None</em>, <em>**options</em>)<a class="headerlink" href="#django.contrib.postgres.indexes.GinIndex" title="永久链接至目标">¶</a></dt>
<dd><p>创建一个 <a class="reference external" href="https://www.postgresql.org/docs/current/gin.html">gin 索引</a> 。</p>
<p>要想在不在 <a class="reference external" href="https://www.postgresql.org/docs/current/gin-builtin-opclasses.html">内置运算符类</a> 的数据类型上使用这个索引，需要在 PostgreSQL 上激活 <a class="reference external" href="https://www.postgresql.org/docs/current/btree-gin.html">btree_gin 扩展</a> 。你可以使用 <a class="reference internal" href="operations.html#django.contrib.postgres.operations.BtreeGinExtension" title="django.contrib.postgres.operations.BtreeGinExtension"><code class="xref py py-class docutils literal notranslate"><span class="pre">BtreeGinExtension</span></code></a> 迁移操作来安装它。</p>
<p>将 <code class="docutils literal notranslate"><span class="pre">fastupdate</span></code> 参数设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code>，以禁用 PostgreSQL 中默认启用的 <a class="reference external" href="https://www.postgresql.org/docs/current/gin-implementation.html#GIN-FAST-UPDATE">GIN 快速更新技术</a> 。</p>
<p>为 <a class="reference external" href="https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-GIN-PENDING-LIST-LIMIT">gin_pending_list_limit</a> 参数提供一个整数字节数，以调整 GIN 待定列表的最大大小，当 <code class="docutils literal notranslate"><span class="pre">fastupdate</span></code> 启用时使用。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.2:</span> <p>增加了位置参数 <cite>*expressions</cite>，以支持函数索引。</p>
</div>
</dd></dl>

</div>
<div class="section" id="s-gistindex">
<span id="gistindex"></span><h2><code class="docutils literal notranslate"><span class="pre">GistIndex</span></code><a class="headerlink" href="#gistindex" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.contrib.postgres.indexes.GistIndex">
<em class="property">class </em><code class="descname">GistIndex</code>(<em>*expressions</em>, <em>buffering=None</em>, <em>fillfactor=None</em>, <em>**options</em>)<a class="headerlink" href="#django.contrib.postgres.indexes.GistIndex" title="永久链接至目标">¶</a></dt>
<dd><p>创建一个 <a class="reference external" href="https://www.postgresql.org/docs/current/gist.html">GiST 索引</a> 。这些索引在空间字段上会自动创建 <a class="reference internal" href="../gis/model-api.html#django.contrib.gis.db.models.BaseSpatialField.spatial_index" title="django.contrib.gis.db.models.BaseSpatialField.spatial_index"><code class="xref py py-attr docutils literal notranslate"><span class="pre">spatial_index=True</span></code></a>。它们在其他类型上也很有用，比如 <code class="xref py py-class docutils literal notranslate"><span class="pre">HStoreField</span></code> 或者 <span class="xref std std-ref">range fields</span>。</p>
<p>要在不在内置的 <a class="reference external" href="https://www.postgresql.org/docs/current/gist-builtin-opclasses.html">gist 操作类</a> 的数据类型上使用这个索引，需要在 PostgreSQL 上激活 <a class="reference external" href="https://www.postgresql.org/docs/current/btree-gist.html">btree_gist 扩展</a> 。你可以使用 <a class="reference internal" href="operations.html#django.contrib.postgres.operations.BtreeGistExtension" title="django.contrib.postgres.operations.BtreeGistExtension"><code class="xref py py-class docutils literal notranslate"><span class="pre">BtreeGistExtension</span></code></a> 迁移操作来安装它。</p>
<p>将 <code class="docutils literal notranslate"><span class="pre">buffering</span></code> 参数设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 或 <code class="docutils literal notranslate"><span class="pre">False</span></code>，手动启用或禁用索引的 <a class="reference external" href="https://www.postgresql.org/docs/current/gist-implementation.html#GIST-BUFFERING-BUILD">buffering build</a> 。</p>
<p>为 <a class="reference external" href="https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS">fillfactor</a> 参数提供一个从  10 到 100 的整数值，以调整索引页的打包程度。PostgreSQL 的默认值是 90。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.2:</span> <p>增加了位置参数 <cite>*expressions</cite>，以支持函数索引。</p>
</div>
</dd></dl>

</div>
<div class="section" id="s-hashindex">
<span id="hashindex"></span><h2><code class="docutils literal notranslate"><span class="pre">HashIndex</span></code><a class="headerlink" href="#hashindex" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.contrib.postgres.indexes.HashIndex">
<em class="property">class </em><code class="descname">HashIndex</code>(<em>*expressions</em>, <em>fillfactor=None</em>, <em>**options</em>)<a class="headerlink" href="#django.contrib.postgres.indexes.HashIndex" title="永久链接至目标">¶</a></dt>
<dd><p>创建一个哈希索引。</p>
<p>为 <a class="reference external" href="https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS">fillfactor</a> 参数提供一个从  10 到 100 的整数值，以调整索引页的打包程度。PostgreSQL 的默认值是 90。</p>
<div class="admonition-use-this-index-only-on-postgresql-10-and-later admonition">
<p class="first admonition-title">只在 PostgreSQL 10 及以后的版本中使用此索引。</p>
<p class="last">哈希索引在 PostgreSQL 中已经存在很长时间了，但在旧版本中，哈希索引存在一些数据完整性问题。</p>
</div>
<div class="versionchanged">
<span class="title">Changed in Django 3.2:</span> <p>增加了位置参数 <cite>*expressions</cite>，以支持函数索引。</p>
</div>
</dd></dl>

</div>
<div class="section" id="s-spgistindex">
<span id="spgistindex"></span><h2><code class="docutils literal notranslate"><span class="pre">SpGistIndex</span></code><a class="headerlink" href="#spgistindex" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.contrib.postgres.indexes.SpGistIndex">
<em class="property">class </em><code class="descname">SpGistIndex</code>(<em>*expressions</em>, <em>fillfactor=None</em>, <em>**options</em>)<a class="headerlink" href="#django.contrib.postgres.indexes.SpGistIndex" title="永久链接至目标">¶</a></dt>
<dd><p>创建 <a class="reference external" href="https://www.postgresql.org/docs/current/spgist.html">SP-GIST 索引</a> 。</p>
<p>为 <a class="reference external" href="https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS">fillfactor</a> 参数提供一个从  10 到 100 的整数值，以调整索引页的打包程度。PostgreSQL 的默认值是 90。</p>
<div class="versionchanged">
<span class="title">Changed in Django 3.2:</span> <p>增加了位置参数 <cite>*expressions</cite>，以支持函数索引。</p>
</div>
</dd></dl>

</div>
<div class="section" id="s-opclass-expressions">
<span id="opclass-expressions"></span><h2><code class="docutils literal notranslate"><span class="pre">OpClass()</span></code> 表达式<a class="headerlink" href="#opclass-expressions" title="永久链接至标题">¶</a></h2>
<div class="versionadded">
<span class="title">New in Django 3.2.</span> </div>
<dl class="class">
<dt id="django.contrib.postgres.indexes.OpClass">
<em class="property">class </em><code class="descname">OpClass</code>(<em>expression</em>, <em>name</em>)<a class="headerlink" href="#django.contrib.postgres.indexes.OpClass" title="永久链接至目标">¶</a></dt>
<dd><p>一个 <code class="docutils literal notranslate"><span class="pre">OpClass()</span></code> 表达式代表了具有自定义 <a class="reference external" href="https://www.postgresql.org/docs/current/indexes-opclass.html">operator class</a> 的  <code class="docutils literal notranslate"><span class="pre">expression</span></code> ，可以用来定义函数索引。要使用它，你需要在你的 <a class="reference internal" href="../../settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a> 中添加 <code class="docutils literal notranslate"><span class="pre">'django.contrib.postgres'</span></code>。将 <code class="docutils literal notranslate"><span class="pre">name</span></code> 参数设置为 <a class="reference external" href="https://www.postgresql.org/docs/current/indexes-opclass.html">operator class</a> 的名称。</p>
<p>例子：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Index</span><span class="p">(</span>
    <span class="n">OpClass</span><span class="p">(</span><span class="n">Lower</span><span class="p">(</span><span class="s1">&#39;username&#39;</span><span class="p">),</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;varchar_pattern_ops&#39;</span><span class="p">),</span>
    <span class="n">name</span><span class="o">=</span><span class="s1">&#39;lower_username_idx&#39;</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
<p>使用 <code class="docutils literal notranslate"><span class="pre">varchar_pattern_ops</span></code> 为 <code class="docutils literal notranslate"><span class="pre">Lower('username')</span></code> 创建索引。</p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">PostgreSQL 特有模型索引</a><ul>
<li><a class="reference internal" href="#bloomindex"><code class="docutils literal notranslate"><span class="pre">BloomIndex</span></code></a></li>
<li><a class="reference internal" href="#brinindex"><code class="docutils literal notranslate"><span class="pre">BrinIndex</span></code></a></li>
<li><a class="reference internal" href="#btreeindex"><code class="docutils literal notranslate"><span class="pre">BTreeIndex</span></code></a></li>
<li><a class="reference internal" href="#ginindex"><code class="docutils literal notranslate"><span class="pre">GinIndex</span></code></a></li>
<li><a class="reference internal" href="#gistindex"><code class="docutils literal notranslate"><span class="pre">GistIndex</span></code></a></li>
<li><a class="reference internal" href="#hashindex"><code class="docutils literal notranslate"><span class="pre">HashIndex</span></code></a></li>
<li><a class="reference internal" href="#spgistindex"><code class="docutils literal notranslate"><span class="pre">SpGistIndex</span></code></a></li>
<li><a class="reference internal" href="#opclass-expressions"><code class="docutils literal notranslate"><span class="pre">OpClass()</span></code> 表达式</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="functions.html"
                        title="上一章">PostgreSQL 特有数据库函数</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="lookups.html"
                        title="下一章">PostgreSQL 特有查找</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/ref/contrib/postgres/indexes.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="functions.html" title="PostgreSQL 特有数据库函数">previous</a>
     |
    <a href="../../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="lookups.html" title="PostgreSQL 特有查找">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>